﻿using System;
using System.Collections.Generic;
using System.Text;

namespace PixentrationEngine
{
    /// <summary>
    /// Class used to save, compare, and report scores.
    /// </summary>
    class ScoreEntry : IComparable<ScoreEntry>
    {
        public String name;
        public int score;
        public String time;
        
        public static String dateFormat = "yyyy-MM-dd @ HH:mm";


        public String Name
        {
            get
            {
                return name;
            }

            set
            {
                name = value;
            }
        }


        public int Score
        {

            get
            {
                return score;
            }

            set
            {
                score = value;
            }

        }


        public String Time
        {

            get
            {
                return time;
            }

            set
            {
                time = value;
            }

        }

        /// <summary>
        /// Displays the attributes of a ScoreEntry object in
        /// the required format.
        /// </summary>
        /// <returns>
        /// A comma-separated list of attributes.
        /// </returns>
        /// <remarks>
        /// Requirements:  8.3.4.
        /// </remarks>
        public override string ToString()
        {
            return Name + "," + Score + "," + Time;
        }

        /// <summary>
        /// Enables a List of ScoreEntry objects
        /// to be sorted by score in descending order.
        /// </summary>
        /// <param name="entry">An instance of the ScoreEntry class.</param>
        /// <returns>
        /// <para>
        /// A positive integer if the value of the score attribute of the calling
        /// object is greater than the value of the score attribute of the argument
        /// that is passed to the method.
        /// </para>
        /// <para>
        /// A negative integer if the value of the score attribute of the calling
        /// object is less than than the value of the score attribute of the argument
        /// that is passed to the method.
        /// </para>
        /// <para>
        /// Zero if the values of the score attributes are equal.
        /// </para>
        /// </returns>
        /// <remarks>
        /// Requirements:  8.3.1, 8.3.2, 8.3.5.
        /// </remarks>
        public int CompareTo(ScoreEntry entry)
        {
            // Multiplying Score.CompareTo(entry.Score) by -1
            // sorts the list in descending order.
            return -1 * Score.CompareTo(entry.Score);
        }


        /// <summary>
        /// Constructor for the ScoreEntry class that is used when
        /// arguments for all three instance variables are supplied
        /// to a request for a new ScoreEntry object.
        /// </summary>
        /// <param name="n">Player's name</param>
        /// <param name="s">Player's score</param>
        /// <param name="t">Time at which score was achieved</param>
        /// <remarks>
        /// Requirements:  8.3.4.
        /// </remarks>
        public ScoreEntry(String n, int s, String t)
        {
            Name = n;
            Score = s;
            Time = t;
        }


        /// <summary>
        /// <para>
        /// Constructor for the ScoreEntry class that is used
        /// when only the player's name and score are supplied
        /// to a request for a new ScoreEntry object.
        /// </para>
        /// <para>
        /// This constructor assigns the current date and time
        /// to the object's Time attribute.
        /// </para>
        /// </summary>
        /// <param name="n">Player's name</param>
        /// <param name="s">Player's score</param>
        /// <remarks>
        /// Requirements:  8.3.1, 8.3.4, 8.3.6.
        /// </remarks>
        public ScoreEntry(String n, int s)
            : this(n, s, DateTime.Now.ToString(dateFormat))
        {
        }


        /// <summary>
        /// <para>
        /// Default constructor for the ScoreEntry class.
        /// </para>
        /// <para>
        /// Supplies dummy values for player's name and
        /// score along with the current date and time
        /// </para>
        /// <para>
        /// This constructor is only used when 10 high
        /// scores have not been recored or when the
        /// saved list of high scores has been corrupted.
        /// </para>
        /// </summary>
        /// <remarks>
        /// Requirements:  8.3.1, 8.3.4, 8.3.6.
        /// </remarks>

        public ScoreEntry()
            : this("NUL", 0, DateTime.Now.ToString(dateFormat))
        {
        }

    }



}
